/**
 *teste
 */
package br.com.tecnove.random.android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import br.com.tecnove.random.android.util.AnimationUtil;
import br.com.tecnove.random.android.util.RandomGenerator;

public class DefaultActivity extends Activity implements View.OnClickListener {

	private Button btn01;
	private Button btn16;
	private Button btnyn;
	private Button btnheadtails;
	private Button btnletter;
	private String yes;
	private String no;
	private String head;
	private String tails;
	private TextView txtLastDefault;
	private String[] YesNo;
	private String[] HeadTails;
	private ScrollView view;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.deflayout);

		yes = getString(R.string.yes);
		no = getString(R.string.no);
		head = getString(R.string.head);
		tails = getString(R.string.tails);

		btn01 = (Button) findViewById(R.id.btn01);
		btn16 = (Button) findViewById(R.id.btn16);
		btnyn = (Button) findViewById(R.id.btnyn);
		btnheadtails = (Button) findViewById(R.id.btnheadtails);
		btnletter = (Button) findViewById(R.id.btnletter);
		txtLastDefault = (TextView) findViewById(R.id.txtLastDefault);

		view = (ScrollView) findViewById(R.id.viewDefaultScrollInside);

		YesNo = new String[] { yes, no };
		HeadTails = new String[] { head, tails };

		btn01.setOnClickListener(this);
		btn16.setOnClickListener(this);
		btnyn.setOnClickListener(this);
		btnheadtails.setOnClickListener(this);
		btnletter.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		String randomedValue = "";
		switch (v.getId()) {
		case R.id.btn01:
			randomedValue = String.valueOf(RandomGenerator.generateFromRange(0, 1));
			break;
		case R.id.btn16:
			randomedValue = String.valueOf(RandomGenerator.generateFromRange(1, 6));
			break;
		case R.id.btnyn:
			randomedValue = RandomGenerator.generateFromStringArray(YesNo);
			break;
		case R.id.btnheadtails:
			randomedValue = RandomGenerator.generateFromStringArray(HeadTails);
			break;
		case R.id.btnletter:
			randomedValue += RandomGenerator.generateLetter();
			break;
		default:
			Log.e("DefaultActivity", "Bad onClick case");
			return;
		}
		Log.d("Sorted", "Default = " + randomedValue);
		AnimationUtil.animateTextView(randomedValue, view, txtLastDefault);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.appdefaultmenu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return ContextMenu.itemClicked(item, this);
	}
}
